import { useRequest } from "ahooks";
import { request } from "@/utils/request";

export const fetchOrderList = async (data: any) => {
  const response = await request("/v1/admin/business_orders", {
    method: "GET",
    params: data,
  });
  return response;
};

export const useOrderList = () => {
  return useRequest((params: any) => fetchOrderList(params), {
    manual: true, // 改为手动触发
  });
};

export const getOrderDetail = async (id: number) => {
  const response = await request(`/v1/admin/business_orders/${id}`, {
    method: "GET",
  });
  return response;
};

export const createOrder = async (data: any) => {
  const response = await request("/v1/admin/business_orders", {
    method: "POST",
    body: JSON.stringify(data),
  });
  return response;
};

export const updateOrder = async (id: number, data: any) => {
  const response = await request(`/v1/admin/business_orders/${id}`, {
    method: "PATCH",
    body: JSON.stringify(data),
  });
  return response;
};

// 获取用户商单列表
export const fetchUserOrderList = async (params: any) => {
  const response = await request("/v1/admin/user_business_orders", {
    method: "GET",
    params,
  });
  return response;
};
export const useUserOrderList = () => {
  return useRequest((params: any) => fetchUserOrderList(params), {
    manual: true, // 改为手动触发
  });
};

// 通过用户商单
export const passOrder = async (id: number) => {
  const response = await request(`/v1/admin/user_business_orders/${id}/approve`, {
    method: "POST",
  });
  return response;
};

// 驳回用户商单
export const rejectOrder = async (id: number) => {
  const response = await request(`/v1/admin/user_business_orders/${id}/reject`, {
    method: "POST",
  });
  return response;
};
